Dynomotion

Group: DynoMotion Message: 1440 From: quelisto Date: 7/6/2011
Subject: Using threads as programming constructs
Hello Tom, I have multiple questions for you about using programming threads (as opposed to the kind of threads cut on a lathe - I'm being pedantic but I want the nature of my question to be clear to other forum users):

1) Are multiple threads allowed to be flashed to each Kflop board as independent programs with assigned thread #'s?

All questions below assume a "yes" answer to #1 above:

2)Are the thread #s the same as those seen in the C-program window, or are threads assigned by order of upload, or some other enumerating mechanism?

3)Are all threads uploaded at once, or are they done one at a time by compiling and then downloading each different *.out file to the board?

4)Will all uploaded threads execute automatically, or do they have to be called by a "master" thread via the "StartThread()" function? If so, which thread is to be the "master thread", or is this simply

5)Is there any limitation on other threads Starting, Pausing, Resuming or Ending other threads?

6) I assume all threads must have their own main() function? If so, is a return from the main the same as executing an End_thread() function?

Thanks!
Group: DynoMotion Message: 1441 From: Tom Kerekes Date: 7/6/2011
Subject: Re: Using threads as programming constructs
Regarding:
 
#1 - We don't recommend flashing programs or configurations into the board unless necessary to run as a stand-alone system (without a PC attached).  It is simpler to have the application set the programs and configuration.  This avoids problems with keeping track of what configuration and source code is flashed in a particular board and such.  It also easily allows re-using threads for different programs at different times.
 
But yes.  KFLOP uses a simplistic approach to multitasking.  There are a maximum of 7 "threads".  Each thread represents a fixed memory space where a single program can be loaded and when executing uses one fixed time slice.  Thread 0 always uses one time slice and is reserved for the System.  See:
 
 
Threads are somewhat expensive.  If N threads are running, the system thread and all the User threads only execute every N time slices.  Consider using a state-machine approach to performing multiple activities concurrently rather than multiple threads.  
 
 
#2 Yes if you have the source code for a C Program loaded into the edit window for a thread then pushing the Save, Compile, Download, Run button will compile the code to be loadable for the corresponding thread memory space, download the code into that thread's memory space, and run that thread.
 
If you write an application to Compile and Download a program you must specify which thread it is to reside in.
 
#3 Programs are downloaded one at a time to a specified thread.
 
#4 We normally refer to sending code to KFLOP as "downloading" (PC is above KFLOP).  There is a call in KMotionDLL called CompileAndLoadCoff() that can be used to compile and load the compiled code into a thread (COFF stands for Common Object File Format).  A separate command is required to then begin execution.  Usually this will be the Console command ExecuteX but it is possible for any other thread to start the execution (this is not commonly required).
 
#5 Not really.  I prefer to tell a thread to terminate itself so it can exit cleanly.
 
#6 Yes.  Each thread is a program which has a main function.  Exiting the thread will terminate the timeslice for that thread.
 
I hope this helps
TK
 


--- On Wed, 7/6/11, quelisto <quelisto@...> wrote:

From: quelisto <quelisto@...>
Subject: [DynoMotion] Using threads as programming constructs
To: DynoMotion@yahoogroups.com
Date: Wednesday, July 6, 2011, 2:16 PM

 
Hello Tom, I have multiple questions for you about using programming threads (as opposed to the kind of threads cut on a lathe - I'm being pedantic but I want the nature of my question to be clear to other forum users):

1) Are multiple threads allowed to be flashed to each Kflop board as independent programs with assigned thread #'s?

All questions below assume a "yes" answer to #1 above:

2)Are the thread #s the same as those seen in the C-program window, or are threads assigned by order of upload, or some other enumerating mechanism?

3)Are all threads uploaded at once, or are they done one at a time by compiling and then downloading each different *.out file to the board?

4)Will all uploaded threads execute automatically, or do they have to be called by a "master" thread via the "StartThread()" function? If so, which thread is to be the "master thread", or is this simply

5)Is there any limitation on other threads Starting, Pausing, Resuming or Ending other threads?

6) I assume all threads must have their own main() function? If so, is a return from the main the same as executing an End_thread() function?

Thanks!